package com.neuedu.his.dao;

import com.neuedu.his.entity.FeeItem;
import com.neuedu.util.JDBCUtil;

import java.util.List;

public class FeeItemDao {


    public List<FeeItem> queryList(Integer registerId) {

        StringBuffer sql = new StringBuffer();

        sql.append(" SELECT 													");
        sql.append("   items.id,                                       ");
        sql.append("   items.register_id,                                       ");
        sql.append("    r.name NAME,                                            ");
        sql.append("   items.item_id,                                           ");
        sql.append("   items.item_name,                                         ");
        sql.append("   items.fee,                                               ");
        sql.append("   items.createtime,                                        ");
        sql.append("   items.STATUS,                                            ");
        sql.append("   items.fee_type                                           ");
        sql.append("                                                            ");
        sql.append(" FROM (                                                     ");
        sql.append("   SELECT                                                   ");
        sql.append("     id,                                           ");
        sql.append("     register_id,                                           ");
        sql.append("     item_id,                                               ");
        sql.append("     item_name,                                             ");
        sql.append("     fee,                                                   ");
        sql.append("     createtime,                                            ");
        sql.append("     STATUS,                                                ");
        sql.append("     '1' fee_type                                           ");
        sql.append("                                                            ");
        sql.append("   FROM                                                     ");
        sql.append("     check_apply                                            ");
        sql.append("   UNION                                                    ");
        sql.append("   ALL                                                      ");
        sql.append("   SELECT                                                   ");
        sql.append("     id,                                           ");
        sql.append("     register_id,                                           ");
        sql.append("     item_id,                                               ");
        sql.append("     item_name,                                             ");
        sql.append("     fee,                                                   ");
        sql.append("     createtime,                                            ");
        sql.append("     STATUS,                                                ");
        sql.append("     '2' fee_type                                           ");
        sql.append("   FROM                                                     ");
        sql.append("     inspect_apply) items                                   ");
        sql.append("     INNER JOIN register r ON items.register_id = r.id	    ");
        sql.append("   WHERE items.register_id = ?								");

//        System.out.println(sql.toString());
        return JDBCUtil.executeQuery(sql.toString(), FeeItem.class, registerId);

    }
}
